package Eyjafjalla.action;

import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;

import java.util.ArrayList;
import java.util.Collections;

public class VoidBirdAction extends AbstractGameAction {
    public VoidBirdAction(AbstractCard.CardType type){
        this.type = type;
        this.actionType = ActionType.CARD_MANIPULATION;
        this.duration = this.startDuration = Settings.ACTION_DUR_FAST;
    }

    @Override
    public void update() {
        if(duration==startDuration){
            AbstractCard card = null;
            ArrayList<AbstractCard> exhaustCopy = new ArrayList<>(AbstractDungeon.player.exhaustPile.group);
            Collections.shuffle(exhaustCopy);
            for(AbstractCard c:exhaustCopy){
                if(c.type == this.type){
                    card = c;
                    break;
                }
            }

            if(card==null){
                this.isDone = true;
                return;
            }

            if (AbstractDungeon.player.hand.size() < 10) {
                AbstractDungeon.player.hand.addToHand(card);
                card.stopGlowing();
                card.unhover();
                card.unfadeOut();
                card.setAngle(0.0F, true);
                card.lighten(false);
                card.drawScale = 0.12F;
                card.targetDrawScale = 0.75F;
                card.applyPowers();
                AbstractDungeon.player.exhaustPile.removeCard(card);
            }

            AbstractDungeon.player.hand.refreshHandLayout();
            AbstractDungeon.player.hand.glowCheck();
        }

        this.tickDuration();
    }

    AbstractCard.CardType type;
}
